package com.zyz.sunliky.service.serviceImpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zyz.sunliky.entity.DepartmentEntity;
import com.zyz.sunliky.mapper.erp.ErpMapper;
import com.zyz.sunliky.mapper.yunshu.DepartmentMapper;
import com.zyz.sunliky.service.DepartmentService;
import jakarta.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper,DepartmentEntity> implements DepartmentService {

    @Autowired
    DepartmentMapper departmentMapper;

    @Autowired
    ErpMapper erpMapper;



    @Transactional
    @Override
    public void savaDepart() {
        List<Map> mapList = new ArrayList<>();
        //查erp部门信息
        List<Map> departList = erpMapper.departList();
        List<String> ysDepartList = departmentMapper.getDepartInfo();
        System.out.println("xingssssssss");


        //判断中间表是否存在这条数据
        for (Map map:departList) {

            if (!ysDepartList.contains(map.get("DCODE"))) {
                mapList.add(map);
            }
        }

        //int num = departmentMapper.insertDeparment(departList);
        if (mapList.size() != 0) {
            int num = departmentMapper.insertDeparment(mapList);
            System.out.println("更新" + num + "条");
        }
        //departmentMapper.insert(departmentEntity);
    }
}
